window.onload = function (){
    findAll();
}

/**
 * 查询所有员工
 */
function findAll(){
    axios.get("/em/findAll").then(resp =>{
        var info = resp.data;
        var str = "";
        info.forEach(n =>{
            str += `<tr><td>${n.name}</td><td>${n.phone}</td>
                    <td>${n.money}</td><td>${n.status}</td><td>`;
            if (n.status == "在职"){
                str += `<input type="button" value="离职" onclick="quit(${n.id})">`;
                str += `<input type="button" value="修改" onclick="location.href='/update.html?id=${n.id}'">`;
            }
            str += `</td></tr>`;
        });
        $("data").innerHTML = str;
    })
}

  function quit(id){
    axios.get("/em/dimission",{
        params:{
            id
        }
    }).then(resp =>{
        if (resp.data == "ok"){
            findAll();
        }
    })
}